package info

import (
	"fmt"
	appVersion "github.com/MzoroHaHa/dev-tools/backend/app/app-version"
	"github.com/MzoroHaHa/dev-tools/backend/app/browser"
	"github.com/MzoroHaHa/dev-tools/backend/app/server"
	"runtime"
)

func PrintInfo() string {
	var str string

	str = "App Info:\n"
	str += fmt.Sprintf("%-20s: %s\n", "Golang", runtime.Version())
	str += fmt.Sprintf("%-20s: %s\n", "OS", runtime.GOOS)
	str += fmt.Sprintf("%-20s: %s\n", "Version", appVersion.VERSION)
	str += fmt.Sprintf("%-20s: %s\n", "Server", server.UsingServer)
	if len(browser.StartError) > 0 {
		str += fmt.Sprintf("%-20s: %s\n", "Chrome Err", browser.StartError)
	}
	str += fmt.Sprintf("%-20s: %s\n", "Chrome Page", browser.GetActivePageUrl())
	str += fmt.Sprintf("%-20s: %s\n", "Chrome Args", browser.GetBrowserArgs())
	return str
}

const GoVersionKey = "GoVersion"
const GoOSKey = "GOOS"
const GoArchKey = "GOARCH"
const VersionKey = "Version"
const ServerKey = "Server"
const ChromePageUrlKey = "ChromePage"
const ChromeArgsKey = "ChromeArgs"
const ChromeErrKey = "ChromeErr"

func RunningInfo() map[string]string {
	info := make(map[string]string)

	info[GoVersionKey] = runtime.Version()
	info[GoOSKey] = runtime.GOOS
	info[VersionKey] = appVersion.VERSION
	info[GoArchKey] = runtime.GOARCH
	info[ServerKey] = fmt.Sprintf("%s", server.UsingServer)
	if len(browser.StartError) > 0 {
		info[ChromeErrKey] = browser.StartError
	}
	info[ChromePageUrlKey] = browser.GetActivePageUrl()
	info[ChromeArgsKey] = browser.GetBrowserArgs()

	return info
}
